def pa(x):
    c=0
    for i in range(2, int(x**0.5)+1):
        if x%i==0:
            c+=1
    if c==0:
        return 1
    else:
        return 0

b=input()
x=0
for i in range(0,4):
    for i in range(4,0, -1):
        if i>1:
            if pa(int(b[1:i]))==1:
                if int(b[1:i])>x:
                    x=int(b[1:i])
print(x)
